package org.jeecg.modules.job.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.job.ums.entity.UmsShieldCompany;
import org.jeecg.modules.job.ums.service.IUmsShieldCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *屏蔽信息管理
 */
@RestController
@RequestMapping("/api/shield")
@Api(tags="移动端屏蔽信息管理模块")
@Slf4j
public class ShiledController{

    @Autowired
    private IUmsShieldCompanyService shieldCompanyService;

    /**
     * 查询屏蔽列表
     */
    @RequestMapping(value = "/getShieldList",method = RequestMethod.GET)
    @ApiOperation(value = "查询屏蔽列表", notes = "查询投递列表")
    public Result<Object> getApplyList(UmsShieldCompany param,
                                       @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                       @RequestParam(name="pageSize", defaultValue="10") Integer pageSize
    ) {
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        param.setMemberId(user.getId());
        IPage<UmsShieldCompany> pageInfo= shieldCompanyService.findPageBySpec(new Page<>(pageNo,pageSize),param);
        return Result.OK(pageInfo);
    }


    /**
     * 添加/更新屏蔽
     */
    @RequestMapping(value = "/addOrUpdateShield",method = RequestMethod.POST)
    @ApiOperation(value = "添加/更新屏蔽", notes = "添加/更新屏蔽")
    public Result<Object> addOrUpdateApply(@RequestBody UmsShieldCompany param) {
        try {
            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            param.setMemberId(user.getId());
            shieldCompanyService.addOrUpdate(param);
            return Result.OK();
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    /**
     * 删除屏蔽
     */
    @RequestMapping(value = "/deleteShield",method = RequestMethod.POST)
    @ApiOperation(value = "删除屏蔽", notes = "删除屏蔽")
    public Result<Object> deleteApply(@RequestBody UmsShieldCompany param) {
        try {
            shieldCompanyService.removeById(param.getId());
            return Result.OK();
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

}



